import request from '@/utils/request'
// import qs from 'qs'

// 获取黑白名单状态
export function getPolicyMode (params) {
  var data = fromData(params)
  return request({
    url: '/policy/getPolicyMode',
    method: 'post',
    data
  })
}

// 修改黑白名单状态
export function editPolicyMode (params) {
  var data = fromData(params)
  return request({
    url: '/policy/changePolicyMode',
    method: 'post',
    data
  })
}

// 获取未命中策略开关
export function getUnmatchMode (params) {
  var data = fromData(params)
  return request({
    url: '/policy/getUnmatchMode',
    method: 'post',
    data
  })
}

// 修改未命中策略开关
export function changeUnmatchMode (params) {
  var data = fromData(params)
  return request({
    url: '/policy/changeUnmatchMode',
    method: 'post',
    data
  })
}

// 获取匹配模式状态
export function getRuldMode (params) {
  var data = fromData(params)
  return request({
    url: '/policy/getRuldMode',
    method: 'post',
    data
  })
}

// 修改规则策略开关
export function changeRuleMode (params) {
  var data = fromData(params)
  return request({
    url: '/policy/changeRuleMode',
    method: 'post',
    data
  })
}

// 获取策略列表
export function getPolicyArray (params) {
  var data = fromData(params)
  return request({
    url: '/policy/getPolicyArray',
    method: 'post',
    data
  })
}

// 移动策略
export function movePolicy (params) {
  var data = fromData(params)
  return request({
    url: '/policy/movePolicy',
    method: 'post',
    data
  })
}

// 编辑策略
export function editPolicy (params) {
  var data = fromData(params)
  return request({
    url: '/policy/editPolicy',
    method: 'post',
    data
  })
}

// 增加策略
export function addPolicy (params) {
  var data = fromData(params)
  return request({
    url: '/policy/addPolicy',
    method: 'post',
    data
  })
}

// 删除策略
export function delPolicy (params) {
  var data = fromData(params)
  return request({
    url: '/policy/del_policy',
    method: 'post',
    data
  })
}

// 删除连接
export function delConnect (params) {
  var data = fromData(params)
  return request({
    url: 'connect/del_connect',
    method: 'post',
    data
  })
}

// 安全引擎重载
export function reloadPolicy (params) {
  var data = fromData(params)
  return request({
    url: '/policy/reloadPolicy',
    method: 'post',
    data
  })
}

// 策略管理--获取是否需要重载
export function reloadPolicyShow (params) {
  var data = fromData(params)
  return request({
    url: '/policy/reloadPolicyShow',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
